home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / iedit210.lha / IEditor / Examples / MemoryObserver / MemoryObs.s < prev   
Text File  |  1995-06-24  |  10KB  |  467 lines

  1. **************************************************************************
  2. *                                                                        *
  3. *  Memory Observer    -    ©1995 Simone Tellini Software                 *
  4. *                                                                        *
  5. *  13/06/95    First Version  by Simone Tellini                          *
  6. *                                                                        *
  7. *  Feel free to modify (and improve ;) this source, but please           *
  8. *  leave my name in it!                       - Thanks, Simone           *
  9. *                                                                        *
  10. **************************************************************************
  11.  
  12.  
  13.     opt !    ; for PhxAss: all optimizations on
  14.  
  15.     incdir /include/
  16.  
  17.     include dos/dos_lib.i
  18.     include exec/exec_lib.i
  19.     include exec/nodes.i
  20.     include intuition/intuition.i
  21.     include intuition/intuition_lib.i
  22.     include gadtools_lib.i
  23.     include libraries/gadtools.i
  24.     include mymacros.i
  25.  
  26.     include sources/mo/MemoryObs_gui.i
  27.  
  28.  
  29.     SECTION    MemObserver,CODE
  30.  
  31.     include iconstartup.i    ; let us start from WB
  32.  
  33.     move.l    4,a6    ; let's open some libs...
  34.     openlib    dos,0,exit
  35.     openlib    gad,0,closedos
  36.     openlib    int,0,closegad
  37.  
  38.     call    CreateMsgPort    ; for timer.device's messages
  39.     move.l    d0,timerport
  40.     beq    closeint
  41.     move.l    d0,a0
  42.     move.b    MP_SIGBIT(a0),d1
  43.     moveq    #1,d0
  44.     lsl.l    d1,d0
  45.     move.l    d0,bitmask
  46.     move.l    d0,timermask
  47.  
  48.     move.l    #IOTV_SIZE,d0
  49.     call    CreateIORequest
  50.     move.l    d0,timerreq
  51.     beq    deleteport
  52.  
  53.     move.l    d0,a1    ; open the timer device
  54.     move.w    #TR_ADDREQUEST,IO_COMMAND(a1)
  55.     move.l    #20,IO_SIZE+TV_MICRO(a1)
  56.     lea    timer_name(pc),a0
  57.     moveq    #UNIT_VBLANK,d0    ; 1/50 sec is what I need
  58.     cldat    d1
  59.     call    OpenDevice
  60.     tst.l    d0
  61.     bne    deletereq
  62.  
  63. * I call the routines of the module MemoryObs_gui.o with 'bsr', so
  64. * I _MUST_ link the two modules together with the SmallCode parameter.
  65.  
  66.     bsr    SetupScreen    ; lock it & get VisualInfos
  67.     tst.l    d0    ; success?
  68.     bne    closescr    ; nope...
  69.  
  70.     move.l    Scr,a0    ; compute the value for the
  71.     move.b    sc_WBorTop(a0),d0    ; height of the window
  72.     ext.w    d0    ; "zipped"
  73.     inc.w    d0    ; height = sc_WBorTop + Font.ta_YSize + 1
  74.     move.l    sc_Font(a0),a0
  75.     add.w    ta_YSize(a0),d0
  76.     move.w    d0,MainZoom+6
  77.  
  78.     sub.w    #10,d0    ; fit the height of the window
  79.     lea    MainWTags,a0    ; to the height of the screen font
  80.     add.w    d0,WT_HEIGHT(a0)
  81.  
  82.     bsr    OpenMainWindow    ; open my window
  83.     tst.l    d0
  84.     bne    closewnd
  85.  
  86.     move.l    MainWnd,a0    ; get its signal bit...
  87.     move.l    wd_UserPort(a0),a0
  88.     move.b    MP_SIGBIT(a0),d1
  89.     moveq    #1,d0
  90.     lsl.l    d1,d0
  91.     or.l    d0,bitmask    ; ...and join it with the timer's one
  92.  
  93.     move.l    timerreq,a1    ; start the timer
  94.     call    SendIO
  95.  
  96. mainloop    move.l    4,a6    ; wait for a signal
  97.     move.l    bitmask,d0
  98.     call    Wait
  99.  
  100.     move.l    timermask,d1    ; is it the timer that calls? :)
  101.     and.l    d0,d1
  102.     beq.s    .notimer    ; nope...
  103.  
  104.     btst    #MONITOR,flags    ; we should monitor the
  105.     beq.s    .nomon    ; memory?
  106.  
  107.     move.l    address,a0
  108.     move.w    size+2(pc),d1
  109.     cmp.w    #2,d1    ; if we aren't monitoring
  110.     beq.s    .noround    ; a single byte, we must
  111.     move.l    a0,d0    ; round to an even address
  112.     and.l    #~1,d0
  113.     move.l    d0,a0
  114. .noround    cldat    d0
  115.     lea    size_routines(pc),a1
  116.     add.w    d1,d1
  117.     add.w    d1,d1
  118.     move.l    0(a1,d1.w),a1
  119.     jsr    (a1)    ; get the value!
  120.     move.l    d0,d7
  121.  
  122.     cmp.l    last,d0    ; did it change since last read?
  123.     beq.s    .nomon
  124.  
  125.     btst    #_BEEP,flags    ; is the beeper active?
  126.     beq.s    .nobeep
  127.     beep        ; a simple but useful macro ;-)
  128.  
  129. .nobeep    move.l    d7,hex
  130.  
  131.     move.l    HexGadget,a0        ; update the displays...
  132.     lea    hex_tag(pc),a3
  133.     bsr    SetTag
  134.  
  135.     move.l    DecGadget,a0
  136.     lea    hex_tag(pc),a3
  137.     bsr    SetTag
  138.  
  139.     move.l    d7,last
  140.  
  141.     lea    last2,a0    ; Replace the 0's with
  142.     move.l    d7,(a0)    ; a space, so the gadget
  143.     moveq    #3,d0    ; displays all the bytes
  144. .search    tst.b    (a0)+    ; I want it to...
  145.     bne.s    .next
  146.     move.b    #' ',-1(a0)
  147. .next    dbra    d0,.search
  148.  
  149.     move.l    AscGadget,a0
  150.     lea    asc_tag(pc),a3
  151.     bsr    SetTag
  152.  
  153.     bsr    Binary
  154.  
  155. .nomon    move.l    4,a6    ; re-start timer...
  156.     move.l    timerreq,a1
  157.     add.l    #20,IO_SIZE+TV_MICRO(a1)
  158.     call    SendIO
  159.  
  160. .notimer    bsr    HandleMainIDCMP    ; check messages from the window
  161.  
  162.     btst    #QUIT,flags    ; should we quit?
  163.     beq    mainloop
  164.  
  165. closewnd    bsr    CloseMainWindow
  166. closescr    bsr    CloseDownScreen    ; unlock & free vi
  167. closetimer    move.l    4,a6    ; close timer.device
  168.     move.l    timerreq,a1
  169.     call    CloseDevice
  170. deletereq    move.l    4,a6    ; delete the io request
  171.     move.l    timerreq,a0
  172.     call    DeleteIORequest
  173. deleteport    move.l    4,a6    ; delete the msg port
  174.     move.l    timerport,a0
  175.     call    DeleteMsgPort
  176. closeint    closelib    int    ; close all the libs
  177. closegad    closelib    gad
  178. closedos    closelib    dos
  179. exit    rts
  180.  
  181. SetTag    move.l    gad_base,a6    ; little sub that sets a tag... ;)
  182.     move.l    MainWnd,a1
  183.     cladd    a2
  184.     call    GT_SetGadgetAttrsA
  185.     rts
  186.  
  187. long    move.l    (a0),d0
  188.     rts
  189. word    move.w    (a0),d0
  190.     rts
  191. byte    move.b    (a0),d0
  192.     rts
  193.  
  194. ******** Routines called by HandleMainIDCMP
  195.  
  196.     XDEF    MainCloseWindow
  197. MainCloseWindow    bset    #QUIT,flags
  198.     rts
  199.  
  200.     XDEF    MainVanillaKey
  201. MainVanillaKey    move.w    im_Code(a5),d5    ; a5 = ^IntuiMsg
  202.     cmp.b    #$20,d5
  203.     blt.s    .raw
  204.     cmp.b    #$7E,d5
  205.     bgt.s    .raw
  206.     or.b    #$20,d5        ; lowercase
  207. .raw    moveq    #KEYS-1,d1
  208.     move.w    d1,d0
  209.     lea    keytable(pc),a0
  210. .search    cmp.b    (a0)+,d5    ; search the key in the table
  211.     dbeq    d1,.search
  212.     tst.w    d1    ; found?
  213.     bge.s    .ok    ; yes!
  214.     rts        ; do nothing.
  215. .ok    sub.w    d1,d0    ; get the right function...
  216.     lsl.w    #2,d0
  217.     lea    funtable(pc),a0
  218.     move.l    0(a0,d0.w),a0
  219.     jmp    (a0)    ; ...and execute it!
  220.  
  221.  
  222.     XDEF    MonClicked
  223. MonClicked    lea    checked_tag(pc),a3    ; toggle the check
  224.     bchg    #MONITOR,flags
  225.     seq    7(a3)
  226.     move.l    MonGadget,a0
  227.     move.l    a3,a4
  228.     bra    SetTag
  229.  
  230.     XDEF    BeepClicked
  231. BeepClicked    lea    checked_tag(pc),a3
  232.     bchg    #_BEEP,flags
  233.     seq    7(a3)
  234.     move.l    BeepGadget,a0
  235.     bra    SetTag
  236.  
  237.     XDEF    SignClicked
  238. SignClicked    lea    checked_tag(pc),a3
  239.     bchg    #SIGN,flags
  240.     seq    7(a3)
  241.     move.l    SignGadget,a0
  242.     move.l    a3,a4
  243.     bsr    SetTag
  244.     tst.b    7(a4)    ; if checked...
  245.     beq.s    .unsigned
  246.     move.b    #'d',sign    ; ...set the "d" fmt type...
  247.     bra.s    .ok
  248. .unsigned    move.b    #'u',sign    ; ...else set the "u"
  249. .ok    move.l    DecGadget,a0
  250.     lea    format_tag(pc),a3
  251.     move.l    #FormatStr,4(a3)
  252.     bra    SetTag
  253.  
  254.     XDEF    AdrClicked
  255. AdrClicked    move.l    AdrGadget,a0
  256.     move.l    gg_SpecialInfo(a0),a0
  257.     move.l    si_Buffer(a0),a0
  258.     moveq    #0,d1
  259.     push.l    a0
  260. .search_end    tst.b    (a0)+    ; count chars
  261.     beq.s    .found
  262.     inc.w    d1
  263.     bra.s    .search_end
  264. .found    pop.l    a0
  265.     move.b    d1,d3    ; store it
  266.     lsr.w    #1,d1    ; divide by 2
  267.     lea    address,a1
  268.     clr.l    (a1)    ; clear the address
  269.     moveq    #4,d2    ; how many bytes shall we skip?
  270.     sub.b    d1,d2
  271.     add.l    d2,a1
  272.     dec.w    d1    ; because of dbra
  273.     and.b    #1,d3    ; the number of chars is even?
  274.     beq.s    .loop    ; yes, alright!
  275.     inc.w    d1    ; no, there's a lone nibble...
  276.     cldat    d2
  277.     dec.l    a1
  278.     bra.s    .secondnibble
  279. .loop    move.b    (a0)+,d0    ; get the first nibble
  280.     bsr.s    ConvertNibble    ; convert it
  281.     move.b    d0,d2    ; store it
  282. .secondnibble    move.b    (a0)+,d0    ; get the second nibble
  283.     bsr.s    ConvertNibble    ; convert it
  284.     lsl.b    #4,d2    ; a little shift... (e.g. 0f  ->  f0)
  285.     or.b    d2,d0    ; join the nibbles (e.g. f0 0f -> ff)
  286.     move.b    d0,(a1)+    ; store the number
  287.     dbra    d1,.loop    ; let's do it again! ;)
  288.     rts
  289.  
  290. ConvertNibble    cmp.b    #'0',d0    ; is it between '0' and '9'?
  291.     blt.s    .error
  292.     cmp.b    #'9',d0
  293.     bgt.s    .hex
  294.     sub.b    #'0',d0    ; ok, transform to binary
  295.     rts
  296. .hex    or.b    #$20,d0    ; lovercase
  297.     cmp.b    #'a',d0    ; is it between 'a' and 'f'?
  298.     blt.s    .error
  299.     cmp.b    #'f',d0
  300.     bgt.s    .error
  301.     sub.b    #'a'-10,d0    ; ok, trasform to binary
  302.     rts
  303. .error    beep
  304.     addq.l    #4,sp    ; remove the return address of
  305.     rts        ; the call so to return to mainloop
  306.  
  307.     XDEF    SizeClicked
  308. SizeClicked    lea    size_tag(pc),a3
  309.     move.w    im_Code(a5),6(a3)
  310.     move.l    SizeGadget,a0
  311.     bsr    SetTag
  312.     lea    setsize_routines(pc),a0
  313.     move.w    im_Code(a5),d0
  314.     add.w    d0,d0
  315.     add.w    d0,d0
  316.     move.l    0(a0,d0.w),a0
  317.     jmp    (a0)
  318.  
  319. LClicked    clr.w    size+2
  320.     move.l    SizeGadget,a0
  321.     lea    size_tag(pc),a3
  322.     bsr    SetTag
  323.     bra.s    SetLong
  324. WClicked    move.w    #1,size+2
  325.     move.l    SizeGadget,a0
  326.     lea    size_tag(pc),a3
  327.     bsr    SetTag
  328.     bra.s    SetWord
  329. BClicked    move.w    #2,size+2
  330.     move.l    SizeGadget,a0
  331.     lea    size_tag(pc),a3
  332.     bsr    SetTag
  333.  
  334. SetByte    lea    format_tag(pc),a3    ; these routines change the
  335.     move.l    #FmtByteHex,4(a3)    ; /look/ of the gadgets... :)
  336.     move.l    HexGadget,a0
  337.     bsr    SetTag
  338.     move.l    AscGadget,a0
  339.     lea    asc_tag(pc),a3
  340.     move.l    #last2+3,4(a3)
  341.     bsr    SetTag
  342.     bra.s    Binary
  343.  
  344. SetLong    lea    format_tag(pc),a3
  345.     move.l    #FmtLongHex,4(a3)
  346.     move.l    HexGadget,a0
  347.     bsr    SetTag
  348.     move.l    AscGadget,a0
  349.     lea    asc_tag(pc),a3
  350.     move.l    #last2,4(a3)
  351.     bsr    SetTag
  352.     bra.s    Binary
  353.  
  354. SetWord    lea    format_tag(pc),a3
  355.     move.l    #FmtWordHex,4(a3)
  356.     move.l    HexGadget,a0
  357.     bsr    SetTag
  358.     move.l    AscGadget,a0
  359.     lea    asc_tag(pc),a3
  360.     move.l    #last2+2,4(a3)
  361.     bsr    SetTag
  362.  
  363. Binary    move.w    size+2(pc),d0    ; how many bytes must we convert?
  364.     add.w    d0,d0
  365.     lea    lenght(pc),a0
  366.     move.w    0(a0,d0.w),d3
  367.     moveq    #4,d4
  368.     sub.w    d3,d4
  369.     dec.w    d4
  370.     lea    bin_space,a1
  371.     move.b    #'%',(a1)+
  372.     lea    last,a2
  373.     add.w    d4,a2    ; skip the bytes not used
  374. .loop    move.b    (a2)+,d1
  375.     moveq    #7,d2    ; Bits in a byte - 1
  376. .convertloop    btst    d2,d1    ; it's as easy as that... :)
  377.     beq.s    .zero
  378.     move.b    #'1',(a1)+
  379.     bra.s    .next
  380. .zero    move.b    #'0',(a1)+
  381. .next    dbra    d2,.convertloop
  382.     move.b    #'.',(a1)+
  383.     dbra    d3,.loop
  384.     clr.b    -(a1)
  385.     move.l    BinGadget,a0
  386.     lea    bin_tag(pc),a3
  387.     bra    SetTag
  388.  
  389. ActivateAdr    move.l    AdrGadget,a0
  390.     move.l    MainWnd,a1
  391.     cladd    a2
  392.     move.l    int_base,a6
  393.     jmp    _LVOActivateGadget(a6)
  394.  
  395.  
  396. gad_name    dc.b 'gadtools.library',0
  397. int_name    dc.b 'intuition.library',0
  398. dos_name    dc.b 'dos.library',0
  399.  
  400. timer_name    dc.b 'timer.device',0
  401.  
  402. version    dc.b '$VER: Memory_Observer 1.0 (14.6.95) by Simone Tellini',0
  403.  
  404. FormatStr    dc.b '#%010l'
  405. sign    dc.b 'u',0
  406.  
  407. FmtLongHex    dc.b '$%08lx',0
  408. FmtWordHex    dc.b '$%04lx',0
  409. FmtByteHex    dc.b '$%02lx',0
  410.  
  411. keytable    dc.b 'm','e','s','l','w','b','a'
  412. KEYS    EQU    *-keytable
  413.  
  414.     cnop 0,4
  415. funtable    dc.l MonClicked,BeepClicked,SignClicked
  416.     dc.l LClicked,WClicked,BClicked
  417.     dc.l ActivateAdr
  418.  
  419. lenght    dc.w 3,1,0
  420.  
  421. size_routines    dc.l long,word,byte
  422. setsize_routines    dc.l SetLong,SetWord,SetByte
  423.  
  424. checked_tag    dc.l GTCB_Checked,0,TAG_END
  425.  
  426. format_tag    dc.l GTNM_Format,FormatStr,TAG_END
  427.  
  428. size_tag    dc.l GTMX_Active
  429. size    dc.l 0,TAG_END
  430.  
  431. hex_tag    dc.l GTNM_Number
  432. hex    dc.l 0,TAG_END
  433.  
  434. asc_tag    dc.l GTTX_Text,last2,TAG_END
  435.  
  436. bin_tag    dc.l GTTX_Text,bin_space,TAG_END
  437.  
  438.  
  439.     SECTION    MemObserver_DataSpace,BSS
  440.  
  441.     XDEF    gad_base
  442.     XDEF    int_base
  443. gad_base    ds.l 1
  444. dos_base    ds.l 1
  445. int_base    ds.l 1
  446.  
  447. timerport    ds.l 1
  448. timerreq    ds.l 1
  449.  
  450. bitmask    ds.l 1
  451. timermask    ds.l 1
  452.  
  453. address    ds.l 1
  454. last    ds.l 1
  455. last2    ds.l 1    ; for the ASCII text gadget
  456.     ds.b 1    ; end of string
  457.  
  458. bin_space    ds.b (4*8)+5
  459.  
  460. flags    ds.b 1
  461. QUIT    EQU    0    ; flags bits
  462. MONITOR    EQU    1
  463. SIGN    EQU    2
  464. _BEEP    EQU    3
  465.  
  466.  
  467.     END